package news.paper.tintuc.tinnong.docbao.doctin;

import tienich360.com.lib.Utils;
import news.paper.tintuc.tinnong.docbao.doctin.util.Constrant;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RelativeLayout;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.TextView;

public class ActivitySettings extends Activity implements OnClickListener {

	private CheckBox checkBox;
	private RelativeLayout relativeLayout;
	private TextView textView;
	private int index;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_setting);
		ImageView imageView = (ImageView) findViewById(R.id.title_button_menu);
		imageView.setOnClickListener(this);
		checkBox = (CheckBox) findViewById(R.id.ac_setting_notify_checkbox);
		checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(CompoundButton buttonView,
					boolean isChecked) {
				System.out.println("Check: " + isChecked);
			}
		});

		relativeLayout = (RelativeLayout) findViewById(R.id.ac_setting_text_size);
		textView = (TextView) findViewById(R.id.ac_setting_text_size_content);
		relativeLayout.setOnClickListener(this);
		index = 1;
		for (int i = 0; i < text_size_value.length; i++) {
			if (Constrant.TEXT_SIZE == text_size_value[i]) {
				index = i;
				i = 5;
			}
		}
		textView.setText(text_size_title[index]);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.title_button_menu:
			finish();
			break;
		case R.id.ac_setting_text_size:
			showChooseTextSize();
			break;
		default:
			break;
		}
	}

	public final CharSequence[] text_size_title = { "Nhỏ", "Trung bình", "Lớn",
			"Rất lớn", "Rất rất lớn" };
	public final int[] text_size_value = { 12, 14, 17, 19, 23 };

	private void showChooseTextSize() {
		AlertDialog.Builder alertG = new AlertDialog.Builder(this);
		alertG.setTitle("Chọn cỡ chữ:");
		alertG.setSingleChoiceItems(text_size_title, index,
				new DialogInterface.OnClickListener() {

					public void onClick(DialogInterface dialog, int which) {
						textView.setText(text_size_title[which]);
						Constrant.TEXT_SIZE = text_size_value[which];
						Utils.saveSubidInt(Constrant.TEXT_SIZE, "TEXT_SIZE",
								ActivitySettings.this);
						dialog.dismiss();
					}
				});
		alertG.show();
	}
}
